/*
	DIMGA
	Distributed Island Model Genetic Algorithm 

	Copyright (c) 2006 Nikola Sivacki nsivacki@gmail.com

	This program is free software; you can redistribute it and/or
	modify in under the terms of the GNU General Public Licence as
	published by the Free Software Foundation; either version 2 of
	the Licence, or [at your option] any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAT PURPOSE. See the
	GNU General Public Licence for more details.

	You should have received a copy of the GNU General Public Licence
	along with this program; if not, write to the Free Software 
	Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// Evaluator.h
#ifndef GAEVALUATOR_H
#define GAEVALUATOR_H

#include <stdio.h>
#include <stdlib.h>
#include "evaluator.h"

class Genotype;

class GAEvaluator : public Evaluator
{
public:
	GAEvaluator(){}

	virtual float Test(unsigned char* _g, long _iSize) { return 0.0f;}

  virtual void Randomize(unsigned char* _g, long _lSize)
  {
      for(int i = 0 ; i < _lSize; i++)
      {
          _g[i] = rand() % 256;
      }
  }

  virtual inline void Mutate(unsigned char * _g, long _lSize, float _fRatio, long _iAmount)
  {
      int offs = rand() % _lSize;
      _g[offs] = ((rand() % 1000) < 1000*_fRatio) ? _iAmount : - _iAmount;
  }

  virtual int getMutationAmount() { return 1;}

	virtual void toFile(unsigned char* _g, long _lSize, const char* file)
  {
    FILE *f = NULL;
    f = fopen(file, "w");
    if (NULL == f)
    {
		  perror("Cannot create file");
	  }

	  long lWritten = fwrite(_g, 1, _lSize, f);
	  if (lWritten != _lSize)
    {
		  perror("Error writing genome");
		}
    fclose(f);
	}

  virtual float getMigrationRatio() { return 0.1f; }

	virtual int getSize() =0;
	
	virtual int getPop() { return 10; }
	
	virtual float getTarget() { return 0.0f;}

  virtual float getMutationRatio() { return 0.1f;}
};


#endif
